package com.dongnam.quanly.common.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.dongnam.quanly.common.model.HoaDon;
import com.dongnam.quanly.common.persistence.HibernateUtil;

public class HoaDonDAO extends ExtendedGenericDao<HoaDon, String> {

	private static final Logger logger = LoggerFactory.getLogger(HoaDonDAO.class);

	public List<String> getListHoaDon(String sodonhang) {

		String queryString = "Select h.soHoaDon from HoaDon h where h.donHang=:sodonhang ";
		Query query = getSession().createQuery(queryString);

		query.setParameter("sodonhang", sodonhang);

		@SuppressWarnings("unchecked")
		List<String> list = query.list();
		return list;

	}

	public boolean checkHoaDon(String sohoadon) {

		String queryString = "Select hd.soHoaDon from HoaDon hd where hd.soHoaDon=:sohoadon";
		Query query = getSession().createQuery(queryString);

		query.setParameter("sohoadon", sohoadon);
		boolean isCheck;
		if (query.list().size() > 0) {
			isCheck = true;
		} else {
			isCheck = false;
		}

		return isCheck;

	}
}
